package com.stylefeng.guns.biz.api.controller;

import java.io.InputStream; 

import com.stylefeng.guns.core.aliyun.AliyunOSSUtil;
import com.stylefeng.guns.core.common.exception.BizExceptionEnum;
import com.stylefeng.guns.core.exception.GunsException; 
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
 

/**
 * pc端登录controller
 * @author zcj
 *
 */
@RequestMapping("/api/pc/upload")
@Controller
public class UploadController {
	
    @Value("${java4all.file.filepath}")
    public String filepath;
	
    @RequestMapping(method = RequestMethod.POST, path = "/uploadImage")
    @ResponseBody
    public String upload(@RequestPart("file") MultipartFile file) {
        String pictureName = ""; 
        try {
        
        	InputStream input = file.getInputStream();
        	pictureName = AliyunOSSUtil.upload(input,file.getName(),filepath);
        } catch (Exception e) {
            throw new GunsException(BizExceptionEnum.UPLOAD_ERROR);
        }
        return pictureName;
    }
}
